package simtester.server

import static org.junit.Assert.*

import grails.test.mixin.*
import grails.test.mixin.support.*
import org.codehaus.groovy.grails.plugins.testing.GrailsMockMultipartFile
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
 */
@TestMixin(GrailsUnitTestMixin)
@TestFor(TestCaseController)
@Mock([User,TestCase,Team])
class TestCaseControllerTests {

    @Test
    void createTestCase() {
        def testcasename = 'UnitTestCase'
        def testusername = 'testuser'
        def testTeamName = 'svt'
        def u = new User(username: testusername, password: 'somepw')
        def team = new Team(name: testTeamName)
        team.addToUsers(u)
        team.save()
        
        def scriptText = "some script\n file text"
        final file = new GrailsMockMultipartFile('script', scriptText.bytes)
        
        request.addFile(file)
        session.user = testusername
        params.name  = testcasename
        controller.create()

        def tc = TestCase.findByOwner(u)
        assert tc.name   == testcasename
        assert tc.script == scriptText
        assert tc.team.name == testTeamName
        assert response.redirectedUrl == '/testRun/create'
    }
}
